import fetch from '@/utils/fetch'
export const certificateConfigList = [{
    value: 'yyyyMMdd',
    label: "年月日",

},
{
    value: 'yyyyMM',
    label: "年月",

},

{
    value: 'yyyy',
    label: "年",

},

{
    value: 'none',
    label: "空",

}
]

export const  findRules = (value) =>  {
    const obj = certificateConfigList.find((item) => {
        return item.value === value
    })
    if (obj) {
        return obj.label
    }
}

export const getCertificateList = async () =>  {
    try {
        let { data } = await fetch.get("/api/certificate-config/list");
        let arr = [];
        data.map((item) => {
            let certificateRules = []
            try {
                certificateRules = JSON.parse(item.certificateRules)
            } catch (error) {
            }
            const [prefix, rule, nums] = certificateRules

            let certificateRulesStr = prefix + findRules(rule) + nums
            arr.push({
                ...item,
                certificateRules,
                certificateRulesStr,
                certificateNamePrefix: `${item.certificateName} （${certificateRulesStr}）`,
            })
        });
        return arr;
    } catch (error) {
        console.log(error);
    }
}
